#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e4 + 5;
const int K = 1e7 + 5;
const int MXK = 10000000;
int n, m;
int head[N], q[105], ans[105];
int ver[N << 1], W[N << 1], Next[N << 1], tot;
void add(int u, int v, int w) {
  ++tot;
  ver[tot] = v;
  W[tot] = w;
  Next[tot] = head[u];
  head[u] = tot;
}
int vis[N], rt, sz[N], mx[N], sum;
void findrt(int u, int fu, int sum) {
  sz[u] = 1, mx[u] = 0;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (vis[v] || v == fu) continue;
    findrt(v, u, sum);
    sz[u] += sz[v];
    mx[u] = max(mx[u], sz[v]);
  }
  mx[u] = max(mx[u], sum - sz[u]);
  if (!rt || mx[rt] > mx[u]) rt = u;
}
int dis[N], num;
bool test[K];
void getdis(int u, int fu, int d) {
  if (d > MXK) return;
  dis[++num] = d;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (vis[v] || v == fu) continue;
    int w = W[i];
    getdis(v, u, d + w);
  }
}
int all;
void calc(int u) {
  num = 0;
  int old = num;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (vis[v]) continue;
    int w = W[i];
    getdis(v, u, w);
    rep(j, 1, m) {
      if (ans[j]) continue;
      rep(k, old + 1, num) {
        if (q[j] >= dis[k] && test[q[j] - dis[k]]) {
          ans[j] = 1;
          break;
        }
      }
    }
    rep(j, old + 1, num) test[dis[j]] = 1, all++;
    old = num;
  }
  rep(i, 1, num) test[dis[i]] = 0;
}
void solve(int u) {
  vis[u] = 1;
  test[0] = 1;
  calc(rt);
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (vis[v]) continue;
    rt = 0;
    if (sz[v] > sz[u]) sz[v] -= sz[u];
    findrt(v, 0, sz[v]);
    solve(rt);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 2, n) {
    int u, v, w;
    cin >> u >> v >> w;
    add(u, v, w), add(v, u, w);
  }
  rep(i, 1, m) cin >> q[i];
  findrt(1, 0, n);
  solve(rt);
  rep(i, 1, m) cout << (ans[i] ? "AYE\n" : "NAY\n");
  return 0;
}